package main

import (
	"fmt"
	"log"
	"os"
	"path/filepath"
)

func main() {
	testOpen()
}
func testCreate() {
	// 创建临时文件，并检查错误
	tf, err := os.CreateTemp("E:\\project-go\\mit6.824-lab1-02\\temp", "mr-temp")
	if err != nil {
		log.Fatalf("cannot create temp file: %v", err)
	}
	tf.Close()
	// 确保关闭文件
	defer os.Remove(tf.Name())

	dir, _ := os.Getwd()
	targetDir := filepath.Join(filepath.Dir(dir), "map-out")
	fmt.Println(targetDir)
	// 构造目标文件名
	fileName := fmt.Sprintf(targetDir+"\\mr-%v-%v", 1, 2)

	// 重命名临时文件到目标位置
	if err := os.Rename(tf.Name(), fileName); err != nil {
		log.Fatalf("error renaming temp file to target path: %v", err)
	}

	log.Printf("Successfully renamed temp file to %s\n", fileName)
}
func testOpen() {
	filename := "E:\\project-go\\mit6.824-lab1-02\\in" + "\\pg-being_ernest.txt"
	file, _ := os.Open(filename)
	print(file.Name())
	defer file.Close()
}
